package ua.com.toltec.flymodemanager;

import android.content.Context;
import android.content.Intent;
import android.provider.Settings;

;

public abstract class RadioServiceUnit {

	public static boolean isAirplaneModeOn(Context context) {
		return Settings.System.getInt(context.getContentResolver(),
				Settings.System.AIRPLANE_MODE_ON, 0) != 0;
	}

	/**
	 * 
	 * @param status
	 */
	public static void setAirplaneMode(Context context) {
		// read the airplane mode setting
		boolean isEnabled = isAirplaneModeOn(context);

		// toggle airplane mode
		Settings.System.putInt(context.getContentResolver(),
				Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1);

		// Post an intent to reload
		Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
		intent.putExtra("state", !isEnabled);
		context.sendBroadcast(intent);
	}

	public static void setAirplaneMode(Context context, Boolean status) {
		// read the airplane mode setting
		boolean isEnabled = isAirplaneModeOn(context);

		if (isEnabled != status) {
			// toggle airplane mode
			Settings.System.putInt(context.getContentResolver(),
					Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1);

			// Post an intent to reload
			Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
			intent.putExtra("state", !isEnabled);
			context.sendBroadcast(intent);
		}

	}

}
